<template>
    <h2 align="center">注册</h2>
    <table border="1" align="center">
        <tr>
            <td>会员编号</td>
            <td>
                <input type="text"  v-model="state.m_Id">
            </td>
        </tr>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="state.m_Name" >
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="state.m_Pwd" >
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="注册" @click="add">
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import {reactive,toRefs} from 'vue';
import axios from 'axios';
import {useRouter} from 'vue-router';
const router = useRouter()

const data = reactive({
    state:{
    m_Id:'',
    m_Name:'',
    m_Pwd:''
    }
})
const {state} = toRefs(data);

const add = ()=>{
    if(state.value.m_Name=="")
        {
            alert('用户名不能为空！');
            return;
        }
        if(state.value.m_Pwd=="")
        {
            alert('密码不能为空！');
            return;
        }
    var reg=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,10}$/
    if(!reg.test(state.value.m_Pwd))
    {
alert("密码需要包含数字、字母，6-10位");
return;
    }
    axios({
        url:'/api/MemberLogin/AddLogin',
        method:'post',
        data:state.value

    })
    .then(res=>{
        console.log(res);
        if(res.data.data>0)
        {
            alert('注册成功！');
            router.push('/LoginDemo')
        }
        else{
            alert('注册失败！');
            return;
        }
        
    })
    .catch(err=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>